/*
 * Copyright (C) 2012 nutmotion <simonotmanuel@gmail.com>
 * Originally released under the tradeUplan project (wiki is at Expression project.wiki is undefined on line 5, column 85 in Templates/Licenses/license-gpl30.txt.)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.nutmotion.model.bean;

import com.nutmotion.model.jpa.Analysis;
import com.nutmotion.model.jpa.Direction;
import com.nutmotion.model.jpa.Signal;
import com.nutmotion.model.jpa.Stock;
import com.nutmotion.model.jpa.Tag;
import com.nutmotion.model.jpa.Timeframe;
import com.nutmotion.model.jpa.User;
import com.nutmotion.service.AnalysisService;
import com.nutmotion.service.DirectionService;
import com.nutmotion.service.SignalService;
import com.nutmotion.service.StockService;
import com.nutmotion.service.TagService;
import com.nutmotion.service.TimeframeService;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

/**
 *
 * @author nutmotion <simonotmanuel@gmail.com>
 */
@ManagedBean
@ApplicationScoped //to be changed to SessionScoped
public class ListsBean {

    private List<Tag> tags;
    private List<Signal> signals;
    private List<Timeframe> timeframes;
    private List<Direction> directions;
    private List<Analysis> analyses;
    private List<Stock> stocks;

    public ListsBean() {
    }

    /**
     * Loads list with the entities that belong to the given user
     */
    public void loadForUser(User user) {
        Tag tagToMatch = new Tag();
        tagToMatch.setUser(user);
        setTags(new TagService().match(tagToMatch));

        Timeframe timeFrameToMatch = new Timeframe();
        timeFrameToMatch.setUser(user);
        setTimeframes(new TimeframeService().match(timeFrameToMatch));
        
        Signal signalToMatch = new Signal();
        signalToMatch.setUser(user);
        setSignals(new SignalService().match(signalToMatch));

        Direction directionToMatch = new Direction();
        directionToMatch.setUser(user);
        setDirections(new DirectionService().match(directionToMatch));
        
        Analysis analysisToMatch = new Analysis();
        analysisToMatch.setUser(user);
        setAnalyses(new AnalysisService().match(analysisToMatch));
       
        Stock stockToMatch = new Stock();
        stockToMatch.setUser(user);
        setStocks(new StockService().match(stockToMatch));
        
        System.out.println("loadForUser : lists loaded");
    }

    /**
     * @return the tags
     */
    public List<Tag> getTags() {
        return tags;
    }

    /**
     * @param tags the tags to set
     */
    public void setTags(List<Tag> tags) {
        this.tags = tags;
    }

    /**
     * @return the signals
     */
    public List<Signal> getSignals() {
        return signals;
    }

    /**
     * @param signals the signals to set
     */
    public void setSignals(List<Signal> signals) {
        this.signals = signals;
    }

    /**
     * @return the timeframes
     */
    public List<Timeframe> getTimeframes() {
        return timeframes;
    }

    /**
     * @param timeframes the timeframes to set
     */
    public void setTimeframes(List<Timeframe> timeframes) {
        this.timeframes = timeframes;
    }

    /**
     * @return the directions
     */
    public List<Direction> getDirections() {
        return directions;
    }

    /**
     * @param directions the directions to set
     */
    public void setDirections(List<Direction> directions) {
        this.directions = directions;
    }

    /**
     * @return the analyses
     */
    public List<Analysis> getAnalyses() {
        return analyses;
    }

    /**
     * @param analyses the analyses to set
     */
    public void setAnalyses(List<Analysis> analyses) {
        this.analyses = analyses;
    }

    /**
     * @return the stocks
     */
    public List<Stock> getStocks() {
        return stocks;
    }

    /**
     * @param stocks the stocks to set
     */
    public void setStocks(List<Stock> stocks) {
        this.stocks = stocks;
    }
}
